import requests
from faker import Faker
faker = Faker(locale='zh_cn')
"""
登录-》新增用户分组—》查询用户分组是否正确添加了
       张三           查询张三存不存在
"""
base_url = "http://8.148.229.201:8899"
# 先发起登录请求
response = requests.post(url=base_url+"/adminapi/login",json={"account":"admin","pwd":"123456","key":"68998c008b4ff","captchaType":"blockPuzzle","captchaVerification":""})
assert response.status_code  == 200
assert response.json()['msg'] == "success"
# 提取token，关联后续接口
token = response.json()['data']['token']

# 发起新增用户分组接口请求
name = str(faker.name()) + "大傻蛋"

response = requests.post(base_url+"/adminapi/user/user_group/save.html",headers={"Authori-zation":"Bearer "+str(token)},json={"group_name":f"{name}"})
# 打印响应体
# print(response.json())
assert response.status_code == 200
assert response.json()['msg'] == "提交成功"
assert response.json()['code'] == '100017'

# 发起查询用户分组接口请求
response = requests.get(base_url+"/adminapi/user/user_group/list?page=1&limit=15",headers={"Authori-zation":"Bearer "+str(token)})
# print(response.json())
assert response.status_code == 200
assert response.json()['msg'] == "success"
# 遍历访问查询用户分组的响应内容
target = True
names = []
for i in response.json()['data']['list']:
    names.append(i['group_name'])
if name in names:
    pass
else:
    raise "傻蛋添加失败，没有查询到！"

